﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Abigail.Model
{
    public class Article
    {
        public decimal PriceIncl
        {
            get { return Math.Round((decimal.Multiply((decimal)price, new decimal(1.25))), 2); }
            set { price = (decimal.Multiply((decimal)value, new decimal(0.8))); }
        }

        public decimal Volume
        {
            get
            {
                decimal temp = new decimal(0.000);
                try
                {
                    temp = Math.Round(decimal.Divide((decimal.Multiply((decimal.Multiply(height, width)), depth)), 1000000), 3);
                }
                catch (DivideByZeroException)
                {
                    new decimal(0.000);
                }
                return temp;
            }
        }
        private int id;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private Model.ArticleCategory category;
        public Model.ArticleCategory Category
        {
            get { return category; }
            set { category = value; }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private decimal amount;
        public decimal Amount
        {
            get { return Math.Round(amount, 2); }
            set { amount = value; }
        }

        private decimal weight;
        public decimal Weight
        {
            get { return Math.Round(weight, 2); }
            set { weight = value; }
        }

        private Model.StockLocation stockLocation;
        public Model.StockLocation StockLocation
        {
            get { return stockLocation; }
            set { stockLocation = value; }
        }

        private decimal replacementCostExcl;
        public decimal ReplacementCostExcl
        {
            get { return Math.Round(replacementCostExcl, 2); }
            set { replacementCostExcl = value; }
        }

        public decimal ReplacementCostIncl
        {
            get { return Math.Round((decimal.Multiply((decimal)replacementCostExcl, new decimal(1.25))), 2); }
            set { replacementCostExcl = (decimal.Multiply((decimal)value, new decimal(0.8))); }
        }

        private decimal price;
        public decimal Price
        {
            get { return Math.Round(price, 2); }
            set { price = value; }
        }

        private string type;
        public string Type
        {
            get { return type; }
            set { type = value; }
        }

        private decimal height;
        public decimal Height
        {
            get { return Math.Round(height, 2); }
            set { height = value; }
        }

        private decimal width;
        public decimal Width
        {
            get { return Math.Round(depth, 2); ; }
            set { width = value; }
        }

        private decimal depth;
        public decimal Depth
        {
            get { return Math.Round(depth, 2); ; }
            set { depth = value; }
        }

        private bool stackable;
        public bool Stackable
        {
            get { return stackable; }
            set { stackable = value; }
        }

        private bool wheels;
        public bool Wheels
        {
            get { return wheels; }
            set { wheels = value; }
        }

        private bool tiltable;
        public bool Tiltable
        {
            get { return tiltable; }
            set { tiltable = value; }
        }

        public Article()
        {
            this.id = 0;
            this.category = null;
            this.name = "";
            this.amount = 0;
            this.weight = 0;
            this.stockLocation = null;
            this.replacementCostExcl = 0;
            this.price = 0;
            this.type = "S";
            this.height = 0;
            this.width = 0;
            this.depth = 0;
            this.stackable = false;
            this.wheels = false;
            this.tiltable = false;
        }

        public Article(int id, ArticleCategory category, string name, decimal amount, decimal weight, StockLocation stockLocation, decimal replacementCost, decimal price, string type, decimal height, decimal width, decimal depth, bool stackable,bool wheels, bool tiltable)
        {
            this.id = id;
            this.category = category;
            this.name = name;
            this.amount = amount;
            this.weight = weight;
            this.stockLocation = stockLocation;
            this.replacementCostExcl = replacementCost;
            this.price = price;
            this.type = type;
            this.height = height;
            this.width = width;
            this.depth = depth;
            this.stackable = stackable;
            this.wheels = wheels;
            this.tiltable = tiltable;
        }

        public string GetValueForString(string property)
        {
            if (property == "id")
                return Id.ToString();
            if (property == "name")
                return Name;
            if (property == "amount")
                return Amount.ToString();
            if (property == "stockLocation")
                return StockLocation.StockLocationCode;
            if (property == "replacementCostIncl")
                return ReplacementCostIncl.ToString();
            if (property == "replacementCostExcl")
                return ReplacementCostExcl.ToString();
            if (property == "category")
                return Category.Name;
            if (property == "priceExcl")
                return Price.ToString();
            if (property == "type")
                return Type;
            if (property == "heigth")
                return Height.ToString();
            if (property == "weight")
                return Weight.ToString();
            if (property == "width")
                return Width.ToString();
            if (property == "depth")
                return Depth.ToString();
            if (property == "stackable")
                if (Stackable)
                    return "Ja";
            if (property == "wheels")
                if (Wheels)
                    return "Ja";
            if (property == "tiltable")
                if(Tiltable)
                    return "Ja";
            if (property == "volume")
                return Volume.ToString();
            if (property == "priceIncl")
                return PriceIncl.ToString();
            if (property == "stockLocationArea")
                return stockLocation.Area.Definition;
            return "Nej";
        }
    }
}
